package View.admin;

import agh.rozproszony.model.User;
import agh.rozproszony.reservations.ReservationsServer;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;

public class UsersTableModel extends AbstractTableModel {

    List<User> users = new ArrayList<User>();

    public void update(List<User> users) {
        this.users = new ArrayList<User>(users);
        fireTableDataChanged();
    }

    @Override
    public int getRowCount() {
        return users.size();
    }

    @Override
    public int getColumnCount() {
        return 4;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        User user = users.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return user.getId();
            case 1:
                return user.getLogin();
            case 2:
                return user.getEmail();
            case 3:
                return user.getType() == User.TYPE_USER ? "Zwykły" : "Administrator";
        }
        throw new RuntimeException("Nieprawidlowy numer kolumny");
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "ID";
            case 1:
                return "Login";
            case 2:
                return "E-Mail";
            case 3:
                return "Typ";
        }
        throw new RuntimeException("Nieprawidłowy numer kolumny");
    }
    
    public User getUserAtRow( int rowId ) {
        return users.get(rowId);
    }
    
    
}
